


class Reactor(object):

    @staticmethod
    def create():
        return SelectReactor()


    def register(self, event, handler):
        raise NotImplementedException, "subclass responsibility"


    def unregister(self, event, handler):
        raise NotImplementedException, "subclass responsibility"


    def run(self, blocking):
        raise NotImplementedException, "subclass responsibility"


    def register_read(self, handler):
        self.register("r", handler)


    def register_write(self, handler):
        self.register("w", handler)


    def unregister_read(self, handler):
        self.unregister("r", handler)


    def unregister_write(self, handler):
        self.unregister("w", handler)



class EventHandler(object):

    def __init__(self, handle):
        self._handle = handle


    def handle(self):
        return self._handle


    def handle_event(self, event):
        if event == "r":
            self.handle_read()
        elif event == "w":
            self.handle_write()
        else:
            raise ValueError, "unknown event type"


    def handle_read(self):
        raise NotImplementedException, "unsupported operation"


    def handle_write(self):
        raise NotImplementedException, "unsupported operation"



from SelectReactor import SelectReactor
